﻿<div style="background-color: ButtonFace;">
    Choose a customer on the list,modify and save data</br>
    <input type="text" jqxb-datasource="custCompactDetail" jqxb-datamember="Name" />
    <input type="text" jqxb-datasource="custCompactDetail" jqxb-datamember="Surname" /><br />
    <input type="button" value="CmdSaveCustomer" onclick="CustomerDetail.saveCustomer()" />
</div>
<script type="text/javascript">
    /*
    *   jQXB - Dynamic-Widget logic
    *
    */
    var CustomerDetail = {}
    CustomerDetail.saveCustomer = function () {
        jQXB.saveJSON('Customer.svc/SaveCustomer', {customer: jQXB.getDataSource('custCompactDetail') }, function (data) { jQXBM.fireMessage(jQXBtopics.MSG_CUSTOMER_UPDATED, data.d, this) });
    }
    CustomerDetail.loadCustomer = function (id) {
        jQXB.getJSON('Customer.svc/getCustomer', { id: id },
                function (data) {
                    jQXB.setDataSource('custCompactDetail', data.d).doBind('custCompactDetail');
                });
    }

    CustomerDetail.clearSubScription = function () {
        jQXBM.unsubscribeMessage(jQXBtopics.MSG_CUSTOMER_SELECTED, CustomerDetail.loadCustomer);
        jQXBM.unsubscribeMessage(jQXBtopics.MSG_PREPARELOADING, CustomerDetail.clearSubScription);
    }

    jQuery(document).ready(function () {
        //alert('Loading');
        jQXBM.subscribeMessage(jQXBtopics.MSG_PREPARELOADING, CustomerDetail.clearSubScription);
        jQXBM.subscribeMessage(jQXBtopics.MSG_CUSTOMER_SELECTED, CustomerDetail.loadCustomer);
        //alert(jQXB.diags.dumpobj(jQXBM.messageSubscribers,"MessageSubscriber","->"));
        //alert('Loaded');
    });
    


</script>
